package com.raining.inningz.ui.common;


import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.raining.inningz.R;
import com.raining.inningz.constants.IDBConstants;
import com.raining.inningz.database.DbManager;
import com.raining.inningz.database.dao.DaoSession;
import com.raining.inningz.database.dao.ScoringTemplates;
import com.raining.inningz.database.dao.ScoringTemplatesDao;
import com.raining.inningz.ui.home.HomePageActivity;
import com.raining.inningz.utils.Utils;


import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;


public class SplashActivity extends Activity implements IDBConstants {

	
	private Context context;
	private Intent i;

	private final int SPLASH_DISPLAY_LENGTH = 500;
	
	DaoSession daoSession;
	private ScoringTemplatesDao scoringTemplatesDao;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash);
		context=this;
		
		daoSession=DbManager.getDbManager(context);
		scoringTemplatesDao=daoSession.getScoringTemplatesDao();
		
		
		
		
		
			
			
			List<ScoringTemplates> scoringTemplates=new ArrayList<ScoringTemplates>();
			
			
			
			scoringTemplates.add(new ScoringTemplates(null, 1, true, "Twenty20", 1, 20, 4, true, 1, true, true, 1, false, true, 11, 10000, 6,null,null,null,null,null,null,null,null,null,null,null));
			scoringTemplates.add(new ScoringTemplates(null, 2, true, "Limited Overs 15- a -side", 1, 15, 3, true, 1, true, true, 1, false, true, 11, 10000, 6,null,null,null,null,null,null,null,null,null,null,null));
			scoringTemplates.add(new ScoringTemplates(null, 3, true, "Limited Overs 25- a -side", 1, 25, 5, true, 1, true, true, 1, false, true, 11, 10000, 6,null,null,null,null,null,null,null,null,null,null,null));
			scoringTemplates.add(new ScoringTemplates(null, 4, true, "Limited Overs 30- a -side", 1, 30, 6, true, 1, true, true, 1, false, true, 11, 10000, 6,null,null,null,null,null,null,null,null,null,null,null));
			scoringTemplates.add(new ScoringTemplates(null, 5, true, "Limited Overs 35- a -side", 1, 35, 7, true, 1, true, true, 1, false, true, 11, 10000, 6,null,null,null,null,null,null,null,null,null,null,null));
			scoringTemplates.add(new ScoringTemplates(null, 6, true, "Limited Overs 40- a -side", 1, 40, 8, true, 1, true, true, 1, false, true, 11, 10000, 6,null,null,null,null,null,null,null,null,null,null,null));
			scoringTemplates.add(new ScoringTemplates(null, 7, true, "Limited Overs 50- a- Side", 1, 50, 10, true, 1, true, true, 1, false, true, 11, 10000, 6,null,null,null,null,null,null,null,null,null,null,null));
			scoringTemplates.add(new ScoringTemplates(null, 8, true, "Custom", 1, 50, 10, true, 1, true, true, 1, false, true, 11, 10000, 6,null,null,null,null,null,null,null,null,null,null,null));
			scoringTemplates.add(new ScoringTemplates(null, 9, false, "Custom 1", 1, 50, 10, true, 1, true, true, 1, false, true, 11, 10000, 6,null,null,null,null,null,null,null,null,null,null,null));
			scoringTemplates.add(new ScoringTemplates(null, 10, null, "Custom 3", 1, 50, 10, true, 1, true, true, 1, false, true, 11, 10000, 6,null,null,null,null,null,null,null,null,null,null,null));
			
			scoringTemplatesDao.insertOrReplaceInTx(scoringTemplates);
		intializeUI();
	}
	
	
	private void intializeUI() {

		new Handler().postDelayed(new Runnable() {

			public void run() {

				i = new Intent(context, HomePageActivity.class);
				
			
				startActivity(i);
				finish();
			}
		}, SPLASH_DISPLAY_LENGTH);

	}

	

}
